﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Komunikator.Web;

namespace Komunikator.Views
{
    public partial class SearchPeopleForm : StackPanel
    {
        private SearchPeopleInfo searchPeopleInfo = new SearchPeopleInfo();

        public SearchPeopleForm()
        {
            InitializeComponent();
            this.DataContext = this.searchPeopleInfo;
        }

        private void buttonSearchPeople_Click(object sender, RoutedEventArgs e)
        {
            SearchResultsSource.Load();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var upd = (User_Personal_Data)((FrameworkElement)sender).DataContext;
            AddNewContactWindow addNewContactWindow = new AddNewContactWindow();

            //Create display name in form "FirstName LastName" or UserName if first and last names are nulls
            string displayName = upd.FirstName ?? String.Empty;
            displayName += displayName != String.Empty ? " " + (upd.LastName ?? String.Empty) : (upd.LastName ?? String.Empty);
            displayName = displayName != String.Empty ? displayName : upd.aspnet_Users.UserName;

            addNewContactWindow.DataContext = new AddNewContactInfo
            {
                UserName = upd.aspnet_Users.UserName,
                FirstName = upd.FirstName,
                LastName = upd.LastName,
                DisplayedName = displayName
            };
            addNewContactWindow.Show();
        }
    }
}
